
             
/**
 * 
 *
 * @File name:  TSuppliersDao.java 
 * @Create on:  2011-10-31 23:59:947
 * @Author   :  陈伟
 *
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */
           
        package com.boho.estates.suppliers.dao;

            
import java.sql.Connection;
import java.util.LinkedList;
import java.util.List;

import cn.boho.framework.po.CQuery;
import cn.boho.framework.po.CQueryFactoryTool;
import cn.boho.framework.po.ComboPager;
import cn.boho.framework.po.DAO;
import cn.boho.framework.po.DynaBeanMap;
import cn.boho.framework.po.Pager;
            
        /**
 * 【供应商信息:T_SUPPLIERS】的Dao操作类
 * 
 */
public class TSuppliersDao extends DAO {
	/**
	* 查询所有【供应商信息:T_SUPPLIERS】信息
	* @param con
	* @return
	* @throws Exception
	* @date 2011-10-31
	* @author 陈伟
	*
	*/
	public static List queryTSuppliers(Connection con, String suppliersType,String suppliersName, String departIds)throws Exception{
		List list = new LinkedList();
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_SUPPLIERS where IS_VALID = 1 ");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		int m=0;
		if(!"".equals(suppliersType)){
			sql.append(" and SUPPLIERS_TYPE = ? ");
			query.setString(++m, suppliersType);
		}
		if(!"".equals(suppliersType)){
			sql.append(" and lower(SUPPLIERS_NAME) = ?");
			query.setString(++m, "%"+suppliersName.toLowerCase()+"%");
		}
		sql.append(" and DEPARTMENT_NO in (").append(departIds).append(")");
		sql.append(" order by SUPPLIERS_NO desc");
		query.setCommand(sql.toString());
		list = query.getDynaBeanMapList("T_SUPPLIERS", con);
		return list;
	}
	/**
	* 分页查询所有【供应商信息:T_SUPPLIERS】信息
	* @param con
	* @param pager
	* @return
	* @throws Exception
	* @date 2011-10-31
	* @author 陈伟
	*
	*/
	public static ComboPager queryTSuppliersByPager(Connection con,Pager pager, String suppliersType, String suppliersName, String suppliersNature, String departIds)throws Exception{
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_SUPPLIERS where IS_VALID = 1");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		int i = 0;
		if(!"".equals(suppliersType)){
			sql.append(" and SUPPLIERS_TYPE = ? ");
			query.setString(++i, suppliersType);
		}
		if(!"".equals(suppliersName)){
			sql.append(" and lower(SUPPLIERS_NAME) like ?");
			query.setString(++i, "%"+suppliersName.toLowerCase()+"%");
		}
		if(!"".equals(suppliersNature)){
			sql.append(" and lower(SUPPLIERS_NATURE) like ?");
			query.setString(++i, "%"+suppliersNature.toLowerCase()+"%");
		}
		sql.append(" and DEPARTMENT_NO in (").append(departIds).append(")");
		sql.append(" order by SUPPLIERS_NO desc");
		query.setCommand(sql.toString());
		System.out.println(query.getCommand());
		return query.getDynaBeanMapComboPager("T_SUPPLIERS", pager,con);
	}
	/**
	* 根据主键【供应商编号:SUPPLIERS_NO|】获得信息
	* @param con
	* @param suppliersNo 供应商编号
	* @return
	* @throws Exception
	* @date 2011-10-31
	* @author 陈伟
	*
	*/
	public static DynaBeanMap getTSuppliersByPk(Connection con,java.lang.Integer suppliersNo)throws Exception{
		DynaBeanMap dynaBeanMap = null;
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_SUPPLIERS where  SUPPLIERS_NO=? and IS_VALID = 1");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		query.setInt(1,suppliersNo);
		dynaBeanMap = query.getDynaBeanMap("T_SUPPLIERS", con);
		return dynaBeanMap;
	}
	
	/**
	* 根据名称【供应商编号:SUPPLIERS_NO|】获得信息
	* @param con
	* @param suppliersNo 供应商编号
	* @return
	* @throws Exception
	* @date 2011-11-30
	* @author 许福辉
	*
	*/
	public static DynaBeanMap getTSuppliersByName(Connection con,String suppliersName, String departIds)throws Exception{
		DynaBeanMap dynaBeanMap = null;
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_SUPPLIERS where SUPPLIERS_NAME=? and IS_VALID = 1");
		sql.append(" and DEPARTMENT_NO in (").append(departIds).append(")");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		query.setString(1,suppliersName);
		dynaBeanMap = query.getDynaBeanMap("T_SUPPLIERS", con);
		return dynaBeanMap;
	}
	
	public static DynaBeanMap getTSuppliersByNameForUpdate(Connection con,String suppliersName, Integer suppliersNo) throws Exception{
		DynaBeanMap dynaBeanMap = null;
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_SUPPLIERS where SUPPLIERS_NAME=? and SUPPLIERS_NO<>? and IS_VALID = 1");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		query.setString(1,suppliersName);
		query.setInt(2, suppliersNo);
		dynaBeanMap = query.getDynaBeanMap("T_SUPPLIERS", con);
		return dynaBeanMap;
	}
}
